package com.twelve.all.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.widget.Toast;

import java.net.URISyntaxException;

/**
 * Created by 张龙臣 on 2019/2/21.
 */

public class MapUtil {

    public static void gotoMap(Context context, String latitude, String longitude, String name) {
        PackageInfo info = PackageMgr.getInstalledPackage(Tools.getAppContext(), "com.baidu.BaiduMap");
        if (info != null) {
            try {
                Intent intent = Intent.getIntent("intent://map/direction?destination=latlng:" + latitude + "," + longitude + "|name:" + name + "&mode=driving&#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end");
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent); //启动调用
            } catch (URISyntaxException e) {

            }
            return;
        }
        info = PackageMgr.getInstalledPackage(Tools.getAppContext(), "com.autonavi.minimap");
        if (info != null) {
            try {
                Intent intent = Intent.getIntent("androidamap://navi?sourceApplication=" + "&poiname=" + name + "&lat=" + latitude + "&lon=" + longitude + "&dev=0");
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            } catch (URISyntaxException e) {

            }
            return;
        }
        Toast.makeText(Tools.getAppContext(), "请安装百度或高德地图", Toast.LENGTH_SHORT).show();
    }
}
